import axiosInstance from './axiosInstance.js';

/**
 * 获取所有的待办事项
 * @param page 页码
 * @param title 标题
 * @param completed 是否完成
 * @returns 待办事项列表
 */
export async function getTodos(page: number = 1, title: string = '', completed: boolean = false) {
    let res = await axiosInstance.get('/todos', {
        params: {
            page,
            title,
            completed
        }
    })
    return res as any
}
/**
 * 获取单个待办事项
 * @param id 待办事项id
 * @returns 待办事项
 */
export async function getTodo(id: number) {
    let res = await axiosInstance.get(`/todos/${id}`)
    return res as any
}
/**
 * 创建待办事项
 * @param title 标题
 * @param completed 是否完成
 * @param description 描述
 * @returns 待办事项
 */
export async function createTodo(title: string, completed: boolean = false, description: string = '') {
    let res = await axiosInstance.post('/todos', {
        title,
        completed,
        description 
    })
    return res as any
}
/**
 * 更新待办事项
 * @param id 待办事项id
 * @param title 标题
 * @param completed 是否完成
 * @param description 描述
 * @returns 待办事项
 */
export async function updateTodo(id: number, title: string, completed: boolean = false, description: string = '') {
    let res = await axiosInstance.put(`/todos/${id}`, {
        title,
        completed,
        description 
    })
    return res as any
}
/**
 * 删除待办事项
 * @param id 待办事项id
 * @returns 待办事项
 */
export async function deleteTodo(id: number) {
    let res = await axiosInstance.delete(`/todos/${id}`)
    return res as any
}
